<template>
  <div style="height: 100vh;">
    <mb-header 
      :menus = "menus" 
      :advanceSearchMeta = "dataModel.searchMeta"
      :signs = "dataModel.supportSigns"
      :time = "dataModel.time"
      :active = "active"
      @easy-search = "easySearch"
      @advance-search = "advanceSearch"
      v-if="$route.path !== '/form/add'"/> 
    <main class="sc-container-outerFrame">
      <router-view :searchVal="searchVal"></router-view>
    </main>
  </div>
</template>

<script>

let appTitle = ""
const makeRoutes = (menus) => {
  return menus && menus.map(item => {
    switch(item.type) {
      case 'form':
      case 'grid': {
        if(!appTitle) {
          appTitle = item.title
        }
        item.router = '/form/' + item.title
        item.href = '#' + item.router
        break
      }
      case 'url': {
        item.href = item.path
        item.isOpenNewPage = true
        break
      }
      default: {
        item.router = '/subpage/' + item.title
        item.href = '#' + item.router
      }
    }

    if(item.sub) {
      item.children = makeRoutes(item.sub)
    }

    return item
  })
}

import MbHeader from './components/mb-header/index.vue'

export default {
  name: 'app',
  components: {
    [MbHeader.name]: MbHeader
  },
  data () {
    return {
      menus: makeRoutes(window.menu),
      dataModel: {},
      searchVal: [],
      active: 0
    }
  },
  computed: {
    // TODO: do somthing...
  },
  beforeRouteEnter (to, from, next) {
    next()
  },
  beforeRouteUpdate (to, from, next) {
    next()
  },
  methods: {
    easySearch(values) {
      this.searchVal = values
    },
    advanceSearch(values) {
      this.searchVal = values
    }
  },
  mounted() {
    if(this.$route.name === "home") {
      this.$router.replace(window.menu[0].router)
    }
  },
  created() {
    this.active = this.$route.params.name;
  },
}
</script>

<style>
  body{
    font-size: 12px !important;
    background-color: #FFFFFF;
  }
  * {
    box-sizing: border-box;
    margin: 0;
    padding: 0; 
  }
</style>

